#! /usr/bin/env python
# -*- coding: utf-8 -*-

# *************************************************************
#     Filename @  my_atoi.py
#       Author @  Huoty
#  Create date @  2016-04-06 12:50:18
#  Description @  
# *************************************************************

def char_to_num(c):
    table = { str(i):i for i in range(10)}
    return table[c]

def atoi(astr):
    strlen = len(astr)
    step = 1
    integer = 0
    for i in range(1, strlen + 1):
        if i > 1:
            step *= 10
        integer += char_to_num(astr[-i]) * step

    return integer

# Script starts from here

print atoi("1234556")
